package com.ruoyi.slope.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.api.domain.SlopeAiPhoto;
import com.ruoyi.slope.api.service.ISlopeAiPhotoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 落石监测图片Controller
 *
 * @author ruoyi
 * @date 2025-07-27
 */
@RestController
@RequestMapping("/api/photo")
public class SlopeAiPhotoController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiPhotoService slopeAiPhotoService;
    /**
     * 查询落石监测图片列表
     */
    @PreAuthorize("@ss.hasPermi('api:photo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiPhoto slopeAiPhoto)
    {
        startPage();
        List<SlopeAiPhoto> list = slopeAiPhotoService.selectSlopeAiPhotoList(slopeAiPhoto);
        return getDataTable(list);
    }

    /**
     * 导出落石监测图片列表
     */
    @PreAuthorize("@ss.hasPermi('api:photo:export')")
    @Log(title = "落石监测图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiPhoto slopeAiPhoto)
    {
        List<SlopeAiPhoto> list = slopeAiPhotoService.selectSlopeAiPhotoList(slopeAiPhoto);
        ExcelUtil<SlopeAiPhoto> util = new ExcelUtil<SlopeAiPhoto>(SlopeAiPhoto.class);
        String path = util.exportExcel(response, list, "落石监测图片数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取落石监测图片详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:photo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeAiPhotoService.selectSlopeAiPhotoById(id));
    }

    /**
     * 新增落石监测图片
     */
    @PreAuthorize("@ss.hasPermi('api:photo:add')")
    @Log(title = "落石监测图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiPhoto slopeAiPhoto)
    {
        return toAjax(slopeAiPhotoService.insertSlopeAiPhoto(slopeAiPhoto));
    }

    /**
     * 修改落石监测图片
     */
    @PreAuthorize("@ss.hasPermi('api:photo:edit')")
    @Log(title = "落石监测图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiPhoto slopeAiPhoto)
    {
        return toAjax(slopeAiPhotoService.updateSlopeAiPhoto(slopeAiPhoto));
    }

    /**
     * 删除落石监测图片
     */
    @PreAuthorize("@ss.hasPermi('api:photo:remove')")
    @Log(title = "落石监测图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeAiPhotoService.deleteSlopeAiPhotoByIds(ids));
    }
}
